accountingIntegrationDashboardApp.controller('maintenanceGlAccountCtrl', ['$scope', '$http', '$log', 'serverDataService', function ($scope, $http, $log, serverDataService){ 

    $scope.companies = [];
    $scope.segments = [];
    $scope.costCenters = [];
    $scope.glAccountTypes = [];
    $scope.entities = [];
    $scope.reconciliationTypes = [];

    $scope.entityName = 'gl-account';

    $scope.setChildScope($scope);

    $scope.renderRecordsFromServer();

    $scope.loadCompanies = function(){
        return $scope.companies.length ? null : serverDataService.getEntityList('company', false)
                .then(function (data){
                    $scope.companies = data.gridRecords;
                });
    };

    $scope.loadSegments = function(){
        return $scope.segments.length ? null : serverDataService.getEntityList('segment', false)
                .then(function (data){
                    $scope.segments = data.gridRecords;
                });
    };

    $scope.loadCostCenters = function(){
        return $scope.costCenters.length ? null : serverDataService.getEntityList('cost-center', false)
                .then(function (data){
                    $scope.costCenters = data.gridRecords;
                });
    };

    $scope.loadGlAccountTypes = function(){
        return $scope.glAccountTypes.length ? null : serverDataService.getEntityList('gl-account-type', false)
                .then(function (data){
                    $scope.glAccountTypes = data.gridRecords;
                });
    };

    $scope.loadEntities = function(){
        return $scope.entities.length ? null : serverDataService.getEntityList('entity', false)
                .then(function (data){
                    $scope.entities = data.gridRecords;
                });
    };

    $scope.loadReconciliationTypes = function(){
        return $scope.reconciliationTypes.length ? null : serverDataService.getEntityList('reconciliation-type', false)
                .then(function (data){
                    $scope.reconciliationTypes = data.gridRecords;
                });
    };

    $scope.addGlAccount = function() {
        $scope.inserted = {
          id: null,
          description: null
        };
        $scope.gridRecords.push($scope.inserted);
    };
}]);